package com.kazimsoylu.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.kazimsoylu.MessengerFunctions;

public class MessengerApp 
{

	private static MessengerApp instance = null;
	
	private JFrame frame;
	private JTextField emailTxtField;
	private JPasswordField passwordField;

	private MessengerApp() {
		initialize();
	}
	
	public static MessengerApp getInstance()
	{
		synchronized ( MessengerApp.class ) 
		{
			if( instance == null )
				instance = new MessengerApp();
		}
		
		return instance;
	}

	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 300, 480);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		emailTxtField = new JTextField();
		emailTxtField.setBounds(41, 70, 207, 27);
		frame.getContentPane().add(emailTxtField);
		emailTxtField.setColumns(10);
		
		//Oturum Açma
		JButton btnOturumAc = new JButton("Oturum Aç");
		btnOturumAc.addActionListener(new ActionListener() 
		{
			public void actionPerformed(ActionEvent arg0) 
			{				
				char[] pass = passwordField.getPassword();
				String password = new String( pass );
				password = password.replace( 'ı' , 'I');

				MessengerFunctions.signIn( emailTxtField.getText() , password);				
			}
		});
		
		btnOturumAc.setBounds(85, 156, 117, 25);
		frame.getContentPane().add(btnOturumAc);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(41, 109, 207, 27);
		passwordField.setLocale( Locale.ENGLISH );
		frame.getContentPane().add(passwordField);
		
		frame.setVisible(true);
	}

	public void setFrame( JFrame frame )
	{
		this.frame.setVisible( false );
		this.frame = frame;
		this.frame.setVisible( true );
	}
}
